Omplus.models.Functionality = Omplus.base.extend(Omplus.models.Object, {
    omplusType:"Functionality",
    controller : "userController",
    value:{
        "functionality":{
            omplusType:"String"
        }
    }

});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"UpdateUser",
    controller : "userController"
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"User",
    controller : "userController",
    value:{
        "name":{
            omplusType:"String"
        },
        "password":{
            omplusType:"String",
            nullable:false
        },
        "confirm_password":{
            omplusType:"String",
            validateWith : "User.password",
            nullable:false
        },
        "last_name":{
            omplusType:"String"
        },
        "username":{
            omplusType:"String"
        },
        "privilege_name" : {
            omplusType:"String"
        },
        "privilege_id" : {
            omplusType:"Number"
        },
        "id" : {
            omplusType:"Number"
        },
        "functionalities":{
            omplusType:"Array",
            omplusProto:"Functionality",
            getOmplusName : function(newValue){
                return this.omplusName + "." + newValue.functionality;
            }
        }
    },
    actions:[
        {
            omplusType:"Get",
            omplusName:"isLoggedIn",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"User"
        },
        {
            omplusType:"Get",
            omplusName:"automaticLogOut",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"User"
        },
        {
            omplusType:"Get",
            omplusName:"logIn",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"User",
            requestModel:"loginDetails",
            start: function(){
                Omplus.globals.getObject("loginErrors").empty();
                Omplus.globals.getObject("loginOverlay").show();
            },
            callback: function(){
                Omplus.globals.getObject("loginOverlay").hide();
                if (Omplus.globals.getObject("User").getStatus() == Omplus.constants.status_ok){
                    Omplus.globals.getObject("loginPanel").hide();
                }
            }
        },
        {
            omplusType:"Set",
            omplusName:"logOut",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"User",
            callback: function(){
                Omplus.globals.getObject("User").setStatus(Omplus.constants.status_error);
                if ($("#loginPanel").css("display") != "block")
                    Omplus.globals.getObject("pagePanel").hide();
            }
        },
        {
            omplusType:"Set",
            omplusName:"update",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"User",
            responseModel:"UpdateUser",
            callback: function(){
            }
        }
    ]
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"UserShort",
    controller : "userController",
    value:{
        "username":{
            omplusType:"String",
            synchroniseWith:"User.username"
        },
        "id":{
            omplusType:"Number",
            synchroniseWith:"User.id"
        }
    }
});


Omplus.base.define(Omplus.models.Model, {

    omplusName:"loginDetails",
    controller : "userController",
    value:{
        "username":{
            omplusType:"String",
            nullable:false
        },
        "password":{
            omplusType:"String",
            nullable:false
        }
    }

});

Omplus.base.define(Omplus.controllers.Controller, {
    omplusName:"userController"
});